package TinyMessage;

use Exporter 'import';
@EXPORT = qw(info warn fatal);

use NoMatchedMessage;

my %warn_codes = (
    'W_OUT_NOT_EXISTS', sub { return "'$_[0]' folder does not exists" },
);

my %fatal_codes = (
    'F_OUT_NOT_EXISTS', sub { return "Ubable to create folder '$_[0]'" },
    'F_FILE_GENERATION', sub { return "Unable to write '$_[0]': $_[1]" },
    'F_TT_ERROR', sub { return $_[0] },
    'F_C_HEADER_PARSER_OPEN', sub { return "Can`t open file '$_[0]': $_[1]" },
    'F_SIGNATURE_SET_GET', sub {
    	my ($sig, @known) = @_;
    	return "Unknown in-project signature '$sig'\n, known signatures: \n'"
    		.join("\n\t", @known); 
    },
    'F_NOT_A_SIGNATURE_OBJECT', sub {return "$_[0] is not valid signature object"},
    'F_INTERNAL', sub {return join('', @_)},
    'F_MODULE_NOT_FOUND', sub {return "Module '$_[0]' not found"},
    'F_NO_MATCHED_CONSTUCTOR', sub{ return noMatchedMessage(@_) },
    'F_PROJECT_HAS_CYCLE', sub{return "Project has cycle beteween modules: ", join(' and ', @_)},
);

sub info {
    my @info =  map {
    	$_ 
#	my $pretty = $_; 
#	$pretty =~ s/\n/\n      /g; 
#	$pretty;
    }   @_;
    print 'info: ', join('', @info), "\n";
}

sub warn {
    my ($warn_code, @context) = @_;
    print "warn[$warn_code]: ", $warn_codes{$warn_code}->(@context), "\n";
}

sub fatal {
    my ($fatal_code, @context) = @_;
    print "fatal[$fatal_code]: ", $fatal_codes{$fatal_code}->(@context), "\n";
    exit 1;
}

1;
